﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using NPSoft.Ferrero.DataBridge.Model;
using NPSoft.Ferrero.Framework.DAL;

namespace NPSoft.Ferrero.DataBridge.DAL
{
    public class New_Mapped_StoreUtil : IDAL<New_Mapped_Store>
    {
        public int Add(New_Mapped_Store info)
        {
            throw new NotImplementedException();
        }

        public int Edit(New_Mapped_Store info)
        {
            throw new NotImplementedException();
        }

        public New_Mapped_Store GetById(long id)
        {
            throw new NotImplementedException();
        }

        public New_Mapped_Store GetById(Guid id)
        {
            throw new NotImplementedException();
        }

        public int Remove(New_Mapped_Store info)
        {
            throw new NotImplementedException();
        }

        public System.Data.DataSet Search(StringBuilder condtion)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// SQL连接
        /// </summary>
        private SqlConnection Connection
        {
            get
            {
                return SqlHelper.GetConnection();
            }
        }


        public ICollection<New_Mapped_Store> SearchCollection(StringBuilder condtion)
        {
            ICollection<New_Mapped_Store> infos = new List<New_Mapped_Store>();
            StringBuilder sql = new StringBuilder();
            sql.Append(@"SELECT ACTIVE_ID,CLIENT_CODE,STORE_CODE,STORE_NAME,TARGET_STORE_CODE from DMS_STORE_MAPPING");

            string sWhere = " where ";
            if (!string.IsNullOrEmpty(condtion.ToString()))
            {

                sql.Append(sWhere + condtion);
            }
            DataSet ds;
            ds = SqlHelper.ExecuteDataset(this.Connection, CommandType.Text, sql.ToString());
            foreach (DataRow row in ds.Tables[0].Rows)
            {
                infos.Add(SetInfo(row));
            }
            return infos;
        }

        public New_Mapped_Store SetInfo(System.Data.DataRow row)
        {
            New_Mapped_Store mapped = new New_Mapped_Store();
            mapped.ACTIVE_ID = SqlHelper.GetString(row, "ACTIVE_ID");
            mapped.CLIENT_CODE = SqlHelper.GetString(row, "CLIENT_CODE");
            mapped.STORE_CODE = SqlHelper.GetString(row, "STORE_CODE");
            mapped.STORE_NAME = SqlHelper.GetString(row, "STORE_NAME");
            mapped.TARGET_STORE_CODE = SqlHelper.GetString(row, "TARGET_STORE_CODE");
         
            return mapped;
        }
    }
}
